package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbUpeModel;
import com.ruoyi.system.service.ITbUpeModelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 流程模型Controller
 * 
 * @author gxt
 * @date 2024-08-23
 */
@RestController
@RequestMapping("/system/model")
public class TbUpeModelController extends BaseController
{
    @Autowired
    private ITbUpeModelService tbUpeModelService;

    /**
     * 查询流程模型列表
     */
    @PreAuthorize("@ss.hasPermi('system:model:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbUpeModel tbUpeModel)
    {
        startPage();
        List<TbUpeModel> list = tbUpeModelService.selectTbUpeModelList(tbUpeModel);
        return getDataTable(list);
    }

    /**
     * 导出流程模型列表
     */
    @PreAuthorize("@ss.hasPermi('system:model:export')")
    @Log(title = "流程模型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbUpeModel tbUpeModel)
    {
        List<TbUpeModel> list = tbUpeModelService.selectTbUpeModelList(tbUpeModel);
        ExcelUtil<TbUpeModel> util = new ExcelUtil<TbUpeModel>(TbUpeModel.class);
        util.exportExcel(response, list, "流程模型数据");
    }

    /**
     * 获取流程模型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:model:query')")
    @GetMapping(value = "/{wfid}")
    public AjaxResult getInfo(@PathVariable("wfid") String wfid)
    {
        return success(tbUpeModelService.selectTbUpeModelByWfid(wfid));
    }

    /**
     * 新增流程模型
     */
    @PreAuthorize("@ss.hasPermi('system:model:add')")
    @Log(title = "流程模型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbUpeModel tbUpeModel)
    {
        return toAjax(tbUpeModelService.insertTbUpeModel(tbUpeModel));
    }

    /**
     * 修改流程模型
     */
    @PreAuthorize("@ss.hasPermi('system:model:edit')")
    @Log(title = "流程模型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbUpeModel tbUpeModel)
    {
        return toAjax(tbUpeModelService.updateTbUpeModel(tbUpeModel));
    }

    /**
     * 删除流程模型
     */
    @PreAuthorize("@ss.hasPermi('system:model:remove')")
    @Log(title = "流程模型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wfids}")
    public AjaxResult remove(@PathVariable String[] wfids)
    {
        return toAjax(tbUpeModelService.deleteTbUpeModelByWfids(wfids));
    }
}
